<template>
  <d-scroll-view  @refresherrefresh="getDetail" :refresher-triggered="triggered">
    <proj-detail-layout :process-instance-id="processInstanceId" :project-number="projectNumber">
      <d-forms label-width="180rpx">
        <d-forms-item label="支持时间" :type="DFormInputType.DATE" :input="form.needSupportTime"></d-forms-item>
        <d-forms-item label="支持地点" :input="form.needSupportLocation"></d-forms-item>
        <d-forms-item label="支持人员">
          <pm-user-select disabled v-model:user-id="form.needSupportEople"></pm-user-select>
        </d-forms-item>
        <d-forms-item label="角色" :type="DFormInputType.DICT" :input="form.role" :dict-type="PM_DICT_TYPE.PROJECT_MEMBER_TYPE"></d-forms-item>
        <d-forms-item label="描述" :input="form.description"></d-forms-item>
      </d-forms>
    </proj-detail-layout>
  </d-scroll-view>
</template>

<script setup lang="ts">
import ProjDetailLayout from "@/components/ProjDetailLayout/index.vue";
import {usePersScheduleApi} from "@/api/pm/project/personnelScheduling";
import {PM_DICT_TYPE} from "@/utils/pmDict";
import {DFormInputType} from "@/utils/enum";

defineOptions({ name: 'PersonnelSchedulingDetail' })

const projectNumber = ref<string>(null);
const processInstanceId = ref<string>(null);
const initForm = {
  projectNumber: undefined,
  role: undefined,
  processInstanceId: undefined,
  applicant: undefined,
  applyTime: undefined,
  needSupportTime: undefined,
  needSupportEople: undefined,
  needSupportLocation: undefined,
  description: undefined,
  storaged: undefined,
  id: undefined,
  result: undefined,
  approvalTime: undefined,
  approvalReason: undefined,
}
const form = ref<DispatchApplyForm>(initForm)
const triggered = ref<boolean>(false);
function getForm() {
  if (processInstanceId.value) {
    triggered.value = true;
    usePersScheduleApi().getPSProcessInstanceId(processInstanceId.value).then((res) => {
      if (res.code === 0 && res.data) {
        form.value = res.data
      }
    }).finally(() => {
      triggered.value = false;
    })
  }
}

onLoad((query) => {
  projectNumber.value = query['project_number']
  processInstanceId.value = query['process_instance_id']
  getForm()
})
</script>

<style scoped lang="scss">

</style>
